var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);
var path = require( "path" );

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));


app.use(function (req, res, next) {
  console.log('middleware');
  req.testing = 'testing';
  return next();
});

app.get('/', function(req, res, next){
  res.render( "index" );
});

app.ws('/websocket', function(ws, req) {
  ws.on('message', function(msg) {
    console.log(msg);
  });
  ws.on( "open", function(){
    console.log( "connect" );
  } );
  ws.on( "close", function( msg ){
    console.log( msg + "closed" );
  } )
  console.log('socket', req.testing);
});

app.listen(3000);
